if [ $# -lt 3 ]; then
    echo "Usage: $0 <input_video output_video_name output_path> "
    exit 1
fi
input=$1
output=$3
logo=/home/work/logo/mylogo.rgba
outputpath=$2/${output}tmp
outputpath_final=$2
echo $outputpath
mkdir -p $outputpath

rm $outputpath/mylogo.fifo
mkfifo $outputpath/mylogo.fifo

#注意 274和117 这个是图片大小如果出错 mencoder会报奇怪的错误
#千万注意
( echo "RGBA32 274 117 5 5 0 1"; cat $logo) > $outputpath/mylogo.fifo &
sleep 1
echo "==================================================================1"
/usr/bin/mencoder $input -o /dev/null -passlogfile $outputpath/${output}_temp.log -ovc x264 -x264encopts bitrate=768:turbo=1:frameref=8:mixed_refs:partitions=all:8x8dct:me=umh:subq=6:trellis=2:threads=auto:pass=1 -nosound -ofps 29.97 -vf bmovl=0:0:$outputpath/mylogo.fifo,harddup -demuxer mov

rm $outputpath/mylogo.fifo
mkfifo $outputpath/mylogo.fifo
( echo "RGBA32 274 117 5 5 0 1"; cat $logo) > $outputpath/mylogo.fifo &

sleep 10
echo "=====================================================================2"
/usr/bin/mencoder  $input -o ${outputpath}/$output.264 -passlogfile $outputpath/${output}_temp.log -ovc x264 -x264encopts  \
bitrate=768:frameref=8:mixed_refs:partitions=all:8x8dct:me=umh:subq=6:trellis=2:threads=auto:pass=2 \
-of rawvideo -nosound -ofps 29.97 -vf bmovl=0:0:$outputpath/mylogo.fifo,harddup -demuxer mov
echo "================================================================================3"
/usr/bin/mplayer $input -af resample=48000:0:0,volnorm=1:0.25 -ao pcm:file=${outputpath}/${output}_temp.wav -vc dummy -vo null -demuxer mov
/usr/bin/neroAacEnc -br 48000 -he -if ${outputpath}/${output}_temp.wav -of ${outputpath}/${output}_temp.mp4
/usr/local/bin/MP4Box -add ${outputpath}/$output.264#video:fps=29.97 ${outputpath}/${output}.m4v
/usr/local/bin/MP4Box -add ${outputpath}/${output}_temp.mp4#audio ${outputpath}/${output}.m4v

/usr/local/bin/MP4Box -inter 500 -itags album=na:artist=na:comment=na:created=na:name=na -lang English ${outputpath}/${output}.m4v

mv  ${outputpath}/${output}.m4v $outputpath_final/
ffmpeg -y -i $outputpath_final/${output}.m4v -ss 5 -vframes 1 -an -sameq -f image2 $outputpath_final/${output}.jpg
ffmpeg -y -i $outputpath_final/${output}.m4v -ss 5 -s 140x102 -vframes 1 -an -sameq -f image2 $outputpath_final/${output}_small.jpg

rm -rf $outputpath

